package app.web.cartoon.report.word.tab;

import java.io.IOException;

import app.excel.cartoon.word.ExcelCartoonWord;
import app.web.cartoon.report.word.tool.CartoonWordReport;
import cn.lily.com.configure.util.ESBSetting;
import cn.lily.com.exception.YaconException;
import cn.lily.com.file.FilePath;
import cn.lily.com.file.zip.ZipFileUtil;
import cn.lily.com.lang.BusinessDate;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;
/**
 * 首字母统计
 * @author JiaJ
 *
 */
public class WordReport extends BusinessPage {

	@Override
	public void page_onLoad() throws YaconException {
		
		 TSqlGrid wordGrid = sqlGrid("wordGrid");
		 wordGrid.setDictTable("LEO_CAN_REPORT_WORD");
		 String sqlString = " select CAN_FIRST,CAN_BASE_NUM,CAN_DETAIL_NUM,to_char(CAN_REP_DATE,'yyyy-mm-dd hh24:mi:ss') CAN_REP_DATE,CAN_REP_OPER "
		 				  + " from ${schema}.LEO_CAN_REPORT_WORD "
		 				  + " order by CAN_FIRST ";
		 wordGrid.setCommSqlStr(sqlString);
		 wordGrid.setEdit(true);

		 wordGrid.createFieldTitle("CAN_FIRST");
		 wordGrid.createFieldTitle("CAN_BASE_NUM");
		 wordGrid.createFieldTitle("CAN_DETAIL_NUM");
		 wordGrid.createFieldTitle("CAN_REP_DATE").setFieldVisible(false);
		 wordGrid.createFieldTitle("CAN_REP_OPER").setFieldVisible(false);
		 
		 TButtonPilot wordGridPilot = ButtonPilot("wordGridPilot");
		 wordGridPilot.setPilotIco("/widget/buttonPilot.gif");
		 wordGridPilot.setPilotText("动漫首字母统计");

		 TButton wordReport = new TButton("wordGridBtn");
		 wordReport.setIcoPath("glyphicon glyphicon-th-large");
		 wordReport.setLabel("动漫首字母统计");
		 wordReport.setViewClick("wordGridBtn_onclick");
		 wordGridPilot.addButtons(wordReport);
		 
		 TButton dataWordExport = new TButton("dataWordExportBtn");
		 dataWordExport.setIcoPath("glyphicon glyphicon-download-alt");
		 dataWordExport.setLabel("首字母导出");
		 dataWordExport.setViewClick("dataWordExportBtn_onclick");	
		 wordGridPilot.addButtons(dataWordExport);

		 wordGrid.setButtonPilot(wordGridPilot);
		 
		 wordGrid.setTopButtonType("all");
		 
		 getPage().addElement(wordGrid);
		
	}
	
	public void refresh(){
		 TSqlGrid wordGrid = sqlGrid("wordGrid");
		 String sqlString = " select CAN_FIRST,CAN_BASE_NUM,CAN_DETAIL_NUM,to_char(CAN_REP_DATE,'yyyy-mm-dd hh24:mi:ss') CAN_REP_DATE,CAN_REP_OPER "
		 				  + " from ${schema}.LEO_CAN_REPORT_WORD "
		 				  + " order by CAN_FIRST ";
		 wordGrid.setCommSqlStr(sqlString);
		 this.setSelfMessage(wordGrid.getDataElement());
	}
	
	public void wordReport(){
		
		try {
			
			CartoonWordReport report = new CartoonWordReport();
			report.inst();
			
		} catch (Exception e) {
			e.printStackTrace();
			this.setSelfMessage("动漫首字母统计失败！");
		}
		
		this.setSelfMessage("动漫首字母统计成功！");
	}
	
	public void wordExport(){
		
		String filePath = "/file/cartoon/word/动漫首字母整理【"+BusinessDate.getdayNumber()+"】.xlsx";
		
		String absolutePath = FilePath.getWebRootPath(filePath);
		
		ExcelCartoonWord excelWord = new ExcelCartoonWord();
		
		excelWord.setFilePath(absolutePath);
		
		excelWord.export();
		
		excelWord.free();
		
		try {
			ZipFileUtil.zipSingleFile(absolutePath, absolutePath+".zip");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.setSelfMessage("/"+ESBSetting.getString("appCode")+filePath+".zip");
		
	}

}
